#ifndef _BUFFER_ALLOC_HPP_20120407
#define _BUFFER_ALLOC_HPP_20120407

#include "base.hpp"

#include "memory_pool.hpp"
#include "circle_buffer.hpp"

namespace mina
{
	class Buffer;

	class BufferAlloc
	{
		public :
			BufferAlloc(int block_size);
			virtual ~BufferAlloc() {}

			int buffer_size() const;

			virtual int free_block() const           = 0;

			virtual Buffer * allocate()              = 0;

			virtual void deallocate(Buffer & buffer) = 0;

		public :
			const int _block_size;
	};

	class PoolBufferAlloc : public BufferAlloc
	{
		public :
			PoolBufferAlloc(MemoryPool & alloc);
			~PoolBufferAlloc();

			virtual int free_block() const { return _alloc.free_block(); }
			
			virtual Buffer * allocate();

			virtual void deallocate(Buffer & buffer);

		public :
			MemoryPool & _alloc;
	};


	class CircleBufferAlloc : public BufferAlloc
	{
		public :
			CircleBufferAlloc(CircleBuffer & alloc);
			~CircleBufferAlloc();

			virtual int free_block() const { return _alloc.free_block(); }
			
			virtual Buffer * allocate();

			virtual void deallocate(Buffer & buffer);

		public :
			CircleBuffer & _alloc;
	};
}

#endif

